﻿using System;
using System.ComponentModel;
using System.Management.Automation;
using System.Collections;
using System.IO;

namespace Quest.FIMPowerShellSnapin
{
    [RunInstaller(true)]
    public class FIMPowerShellSnapin : PSSnapIn
    {
        public override string Name
        {
            get { return "Quest.FIMPowerShellSnapin"; }
        }

        public override string Vendor
        {
            get { return "Quest Software"; }
        }

        public override string Description
        {
            get { return "This snap-in contains cmdlets for Microsoft Forefront Identity Manager (FIM)."; }
        }

        public override string[] Formats
        {
            get
            {
                return GetFileNames("Format");
            }
        }

        public override string[] Types
        {
            get
            {
                return GetFileNames("Types");
            }
        }

        private string[] GetFileNames(string suffix)
        {
            // we assume the types file is in the same folder as the snap-in dll
            string snapinName = GetType().Module.FullyQualifiedName;

            string resultFilename =
                Path.ChangeExtension(snapinName, suffix + ".ps1xml");

            // w/o this check if the file is missing we'll get an error when opening the PS console 
            if (File.Exists(resultFilename))
            {
                return new string[] { resultFilename };
            }
            else
            {
                return null;
            }
        }
    }
}
